package com.ftg.learn.back.pattern.factory;

/**
 *
 * 面向父类编程 面向接口编号
 *
 * @author kangjx
 * @createTime 2022/9/1
 */
public class LearnFactoryPatter {

    public static void main(String[] args) {
//        Product p = ProductFactory.getProductInfo("food");
//        Product p1 = ProductFactory.getProductInfo("electronic");
//
//        System.out.println(p1.info());
//        System.out.println(p.info());
//
//        /**
//         * 高级一些 ， 设计感要强一些
//         */
//        Product p2 = ProductFactory.getProductInfo(ProductType.FOOD);

        /**
         * 反射方式
         */
//        String personPath = "com.ftg.learn.back.pattern.factory.FoodImpl";
//        Class c = null;
//        try {
//            c = Class.forName(personPath);
//            Product p3 = ProductFactory.getProductInfo(c);
//            System.out.println(p3.info());
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }

        Product p4 = ProductFactory.getProductInfo(FoodImpl.class);
        Product p5 = ProductFactory.getProductInfo(FoodImpl.class);
        System.out.println(p4 == p5);
        System.out.println(p4.info());
        System.out.println(p5.info());

    }

}
